package com.ygqh.baby.excel.domain;

import com.foxinmy.weixin4j.util.StringUtil;
import com.ygqh.baby.ao.Logistics;
import com.ygqh.baby.excel.annotation.ExcelField;

import java.util.Date;

/**
 * 〈〉
 *
 * @author guohao
 * @date 2019/4/18 18:17
 * @since 1.0.0
 */
public class OrderSendEntity extends AbstractExcelReadEntity {

    @ExcelField(head = "订单编号")
    private String orderId;

    @ExcelField(head = "商品名称")
    private String productName;

    @ExcelField(head = "SKU编码")
    private String skuCode;

    @ExcelField(head = "物流公司")
    private String logisticsName;

    @ExcelField(head = "物流单号")
    private String expressCode;

    /**
     * ===========业务数据============================
     */
    private Date sendTime = new Date();

    private String logisticsCode;

    /**
     * ============业务数据===========================
     */

    public String getLogisticsCode() {
        return StringUtil.isNotBlank(logisticsCode) ? logisticsCode : findLogisticsCode(logisticsName);
    }

    public void setLogisticsCode(String logisticsCode) {
        this.logisticsCode = logisticsCode;
    }

    public Date getSendTime() {
        return sendTime;
    }

    public void setSendTime(Date sendTime) {
        this.sendTime = sendTime;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getSkuCode() {
        return skuCode;
    }

    public void setSkuCode(String skuCode) {
        this.skuCode = skuCode;
    }

    public String getLogisticsName() {
        return logisticsName;
    }

    public void setLogisticsName(String logisticsName) {
        this.logisticsName = logisticsName;
    }

    public String getExpressCode() {
        return expressCode;
    }

    public void setExpressCode(String expressCode) {
        this.expressCode = expressCode;
    }


    public String findLogisticsCode(String expressCompany) {
        expressCompany = expressCompany == null ? "" : expressCompany;
        Logistics[] logistics = Logistics.values();
        for (Logistics item : logistics) {
            if (item.getTitle().equals(expressCompany)) {
                return item.name();
            }
        }
        // 按名称模糊锁定
        if (expressCompany.startsWith("申通")) {
            return "STO";
        } else if (expressCompany.startsWith("圆通")) {
            return "YTO";
        } else if (expressCompany.startsWith("中通")) {
            return "ZTO";
        }
        return null;
    }

}
